package com.ibiaoke.customer.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.customer.entity.DepositRecorder;
import com.ibiaoke.customer.entity.DepositRecorderExample;
import com.ibiaoke.customer.mapper.DepositMapper;
import com.ibiaoke.customer.mapper.DepositRecorderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2017/6/20.
 */
@Repository
public class DepositRecorderDao extends BaseDao<DepositRecorder,DepositRecorderExample,Integer,DepositRecorderMapper>{
    @Autowired
    private DepositRecorderMapper depositRecorderMapper;

    @Override
    public DepositRecorderMapper getMapper() {
        return depositRecorderMapper;
    }

    public List<DepositRecorder> depositRecorderList(Integer customerId, Page page) {
        DepositRecorderExample example = new DepositRecorderExample();
        if(customerId!=null){
             example.createCriteria().andCustomerIdEqualTo(customerId);
        }
        example.createCriteria().andTradeTypeEqualTo(CommonConsts.YES);
        example.setOrderByClause("create_time desc");
        page.setTotalCount(depositRecorderMapper.countByExample(example));
        example.setLimitStart(page.limitStart());
        example.setLimitEnd(page.limitEnd());
        return depositRecorderMapper.selectByExample(example);
    }

    public List<DepositRecorder> listDepositRecorderByCustomerId(Integer customerId,Page page) {
        DepositRecorderExample example = new DepositRecorderExample();
        example.createCriteria().andCustomerIdEqualTo(customerId);

        page.setTotalCount(depositRecorderMapper.countByExample(example));
        example.setLimitStart(page.limitStart());
        example.setLimitEnd(page.limitEnd());
        example.setOrderByClause("update_time desc");

        return depositRecorderMapper.selectByExample(example);
    }
}
